//
//  YZSilkBannerViewController.m
//  FastDoctor
//
//  Created by yongzhen on 16/9/7.
//  Copyright © 2016年 yongzhen. All rights reserved.
//

#import "YZSilkBannerViewController.h"
#import "Masonry.h"
#import "YZDoctorTimeLayOut.h"
#import "KYDocDutiesModel.h"
static NSString *itemid = @"itemid";
@interface YZSilkBannerViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,weak)UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *dutiesModel;

@end

@implementation YZSilkBannerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     self.view.backgroundColor = [UIColor whiteColor];
    [self loadDocDuties];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:itemid];
    
    
    
    [self setupUI];
}
-(void)setupUI
{
    // 创建collectionView
    UICollectionViewLayout *layout = [[YZDoctorTimeLayOut alloc] init];
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.backgroundColor = [UIColor redColor];
    collectionView.pagingEnabled = YES;
    [self.view addSubview:collectionView];
    
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.top.bottom.equalTo(self);
        
    }];
    self.collectionView = collectionView;
    
    
    
    
//    UILabel *Label1 = [[UILabel alloc] init];
//    Label1.tintColor = [UIColor blackColor];
//    Label1.font = [UIFont systemFontOfSize:19];
//    Label1.text = @"请提前一天预订";
//    [Label1 sizeToFit];
//    Label1.textColor = [UIColor grayColor];
//    Label1.font = [UIFont systemFontOfSize:15];
//    [self.view addSubview:Label1];
//    [Label1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.view).offset(30);
//        make.left.mas_equalTo(self.view).offset(15);
//    }];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
     UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:itemid forIndexPath:indexPath];
    [self loadDateSelected];
    UIView *view = [[UIView alloc] initWithFrame:cell.contentView.frame];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    //        self.view = view;
    [cell.contentView addSubview:view];
    
//    CGFloat height = [[UIDevice currentDevice].model hasPrefix:@"iPad"] ? 450 : 300;
//    FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, height)];
//    calendar.dataSource = self;
//    calendar.delegate = self;
//    //        calendar.allowsSelection = false;
//    calendar.showsPlaceholders = true;
//    calendar.allowsMultipleSelection = NO;
//    calendar.backgroundColor = [UIColor whiteColor];
//    calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase|FSCalendarCaseOptionsWeekdayUsesSingleUpperCase;
//    [view addSubview:calendar];
//    [calendar selectDate:[calendar dateWithYear:2015 month:12 day:1]];
//    self.calendar = calendar;
//}
    
    return cell;
}
- (void)loadDocDuties {
    [[CCKYTools sharedTools] doctorDutiesWithSuccess:^(NSDictionary *response) {
        //        NSLog(@"%@",response);
        //解析duties数组
        NSArray *duties = response[@"duties"];
        NSMutableArray *dutiesModles = [NSMutableArray array];
        for (NSDictionary *dict in duties) {
            KYDocDutiesModel *model = [KYDocDutiesModel yy_modelWithDictionary:dict];
            [dutiesModles addObject:model];
        }
        NSArray *dutiesModel = dutiesModles;
        self.dutiesModel = dutiesModel;
        
        //        NSLog(@"%lu",(unsigned long)self.dutiesModel.count);
        
        //解析zuozhen_infos数组
        //        NSDictionary *zuozhen = response[@"zuozhen_infos"][0];
        //        KYDocDutiesModel *zuozhenmodel = [KYDocDutiesModel yy_modelWithDictionary:zuozhen];
        
        
        //        //解析start_date和period
        //        KYDocDutiesModel *start_dateModel = [KYDocDutiesModel yy_modelWithDictionary:response];
        
        //        NSLog(@"%@",dutiesModle);
        //        NSLog(@"%@",zuozhenmodel);
        //        NSLog(@"%@",start_dateModel);
    }];
}

- (void)loadDateSelected {
    
    //    NSLog(@"%lu",(unsigned long)self.dutiesModel.count);
    
    NSMutableArray *duties = [NSMutableArray array];
    for (int i = 0; i < self.dutiesModel.count; i++) {
        KYDocDutiesModel *model = self.dutiesModel[i];
        NSString *str = model.duty_date;
        //        NSLog(@"%@", model.duty_date);
        [duties addObject:str];
    }
    
    UIColor *dutiesColor = [UIColor colorWithHex:0x4DCECB];
    
    NSMutableDictionary *dutiesDict = [NSMutableDictionary dictionary];
    for (int i = 0; i < duties.count; i++) {
        NSString *str = duties[i];
        NSString *str_1 = [str stringByReplacingOccurrencesOfString:@"-" withString:@"/"];
        [dutiesDict setObject:dutiesColor forKey:str_1];
    }
    
    NSMutableDictionary *dutiesDictSelected = [NSMutableDictionary dictionary];
    for (int i = 0; i < duties.count; i++) {
        NSString *str = duties[i];
        NSString *str_1 = [str stringByReplacingOccurrencesOfString:@"-" withString:@"/"];
        [dutiesDictSelected setObject:[UIColor colorWithHex:0xEE9EB4] forKey:str_1];
    }
   
    
    self.fillDefaultColors = dutiesDict;
    
    self.fillSelectionColors = dutiesDictSelected;
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
